//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com;

import com.mdx.api.autocode.fileread.*;
import com.util.ReadUtil;
import org.netbeans.lib.awtextra.AbsoluteConstraints;
import org.netbeans.lib.awtextra.AbsoluteLayout;

import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class GuiMain extends JFrame {
    private DefaultTableModel model;
    private Object[][] obj;
    private List<ApiInfo> data;
    private List<Api> listApi;
    private String directoryPath;
    private ApiInfoList apiInfoList;
    private TextField content;
    private JTextField directory;
    private JTextArea editor;
    private JButton jButton3;
    private JMenu jMenu1;
    private JMenu jMenu2;
    private JMenuBar jMenuBar1;
    private JMenuItem jMenuItem1;
    private JMenuItem jMenuItem2;
    private JPanel jPanel1;
    private JPanel jPanel2;
    private JPanel jPanel3;
    private JScrollPane jScrollPane1;
    private JScrollPane jScrollPane2;
    private JTable jTable1;
    private PopupMenu popupMenu1;
    private JButton search;

    public GuiMain() {
        this.initComponents();
        this.initView();
        this.setData("D:\\");
        this.setJtableListener();
    }

    public void setData(String str) {
        this.apiInfoList = new ApiInfoList();
        File file = new File(str);

        try {
            this.apiInfoList.set(file);
            this.data = this.apiInfoList.apiInfoList;
            this.listApi = ReadUtil.spliceList(this.data);
            this.setListData(this.listApi);
            this.jTable1.setModel(new DefaultTableModel(this.obj, new String[]{"名称"}));
        } catch (Exception var4) {
            Logger.getLogger(GuiMain.class.getName()).log(Level.SEVERE, (String)null, var4);
        }

    }

    public void setDataToView(int offset) {
        int index = this.jTable1.getSelectedRow();
        String str = (String)this.jTable1.getModel().getValueAt(index + offset, 0);
        str = ReadUtil.findApiId(str);

        for(int i = 0; i < this.listApi.size(); ++i) {
            String id = ((Api)this.listApi.get(i)).getId();
            if(str.equals(id)) {
                Api api = (Api)this.listApi.get(i);
                ArrayList listapiParam = ((Api)this.listApi.get(i)).getParamsList();
                String tempParam = "";
                String explainApiParam = "";
                Iterator temp = listapiParam.iterator();

                while(temp.hasNext()) {
                    ApiParam explainClassparam = (ApiParam)temp.next();
                    tempParam = tempParam + explainClassparam.toString() + "\n";
                    ApiMessage list = this.apiInfoList.findMsg(explainClassparam.type);
                    if(list != null) {
                        explainApiParam = explainApiParam + list + "\n";
                    }
                }

                String var16 = "/**\n@api " + api.getId() + " " + api.getId() + "//" + api.getRemark() + "\n" + tempParam + "@return " + api.getReturn() + "\n*/";
                String var17 = "";
                ArrayList var18 = api.getRetn().getParams();
                Iterator var13 = var18.iterator();

                while(var13.hasNext()) {
                    ClassParam classParam = (ClassParam)var13.next();
                    ApiMessage apiMessage = api.getMsg(classParam.type);
                    if(apiMessage != null) {
                        var17 = var17 + apiMessage + "\n";
                    }
                }

                this.editor.setText(var16 + "\r\n\r\n" + api.getRetn() + "\r\n\r\n参数:\r\n\r\n" + explainApiParam + "返回结果\n" + var17);
            }
        }

    }

    public void setJtableListener() {
        this.jTable1.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                GuiMain.this.setDataToView(0);
            }
        });
    }

    public void setListData(List<Api> list) {
        this.obj = new Object[list.size()][1];

        for(int i = 0; i < list.size(); ++i) {
            this.obj[i][0] = ((Api)list.get(i)).getId() + "(" + ((Api)list.get(i)).getRemark() + ")";
        }

        this.jTable1.setModel(new DefaultTableModel(this.obj, new String[]{"名称"}));
    }

    private void initComponents() {
        this.popupMenu1 = new PopupMenu();
        this.jPanel3 = new JPanel();
        this.jPanel2 = new JPanel();
        this.jScrollPane1 = new JScrollPane();
        this.editor = new JTextArea();
        this.jPanel1 = new JPanel();
        this.jScrollPane2 = new JScrollPane();
        this.jTable1 = new JTable();
        this.search = new JButton();
        this.jButton3 = new JButton();
        this.directory = new JTextField();
        this.content = new TextField();
        this.jMenuBar1 = new JMenuBar();
        this.jMenu1 = new JMenu();
        this.jMenuItem1 = new JMenuItem();
        this.jMenu2 = new JMenu();
        this.jMenuItem2 = new JMenuItem();
        this.popupMenu1.setLabel("popupMenu1");
        this.setDefaultCloseOperation(3);
        this.setTitle("Api查看");
        this.setAutoRequestFocus(false);
        this.setBackground(new Color(133, 167, 175));
        this.addComponentListener(new ComponentAdapter() {
            public void componentResized(ComponentEvent evt) {
                GuiMain.this.formComponentResized(evt);
            }
        });
        this.getContentPane().setLayout(new AbsoluteLayout());
        this.jPanel3.setLayout(new AbsoluteLayout());
        this.jPanel2.setBorder(BorderFactory.createTitledBorder("选择区域"));
        this.editor.setEditable(false);
        this.editor.setColumns(20);
        this.editor.setRows(5);
        this.editor.setBorder(BorderFactory.createTitledBorder(""));
        this.editor.addComponentListener(new ComponentAdapter() {
            public void componentResized(ComponentEvent evt) {
                GuiMain.this.editorComponentResized(evt);
            }
        });
        this.jScrollPane1.setViewportView(this.editor);
        GroupLayout jPanel2Layout = new GroupLayout(this.jPanel2);
        this.jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING, jPanel2Layout.createSequentialGroup().addContainerGap(22, 32767).addComponent(this.jScrollPane1, -2, 456, -2).addContainerGap()));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(this.jScrollPane1, -1, 576, 32767).addContainerGap()));
        this.jPanel3.add(this.jPanel2, new AbsoluteConstraints(410, 10, -1, -1));
        this.jPanel1.setBorder(BorderFactory.createTitledBorder("功能"));
        this.jPanel1.setCursor(new Cursor(0));
        this.jPanel1.setLayout(new AbsoluteLayout());
        this.jTable1.setModel(new DefaultTableModel(new Object[][]{{null}, {null}, {null}, {null}}, new String[]{"名称"}) {
            Class[] types = new Class[]{String.class};

            public Class getColumnClass(int columnIndex) {
                return this.types[columnIndex];
            }
        });
        this.jScrollPane2.setViewportView(this.jTable1);
        this.jPanel1.add(this.jScrollPane2, new AbsoluteConstraints(20, 100, 320, 500));
        this.search.setText("搜索");
        this.search.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiMain.this.searchActionPerformed(evt);
            }
        });
        this.jPanel1.add(this.search, new AbsoluteConstraints(240, 60, 100, 30));
        this.jButton3.setText("打开文件夹");
        this.jButton3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiMain.this.jButton3ActionPerformed(evt);
            }
        });
        this.jPanel1.add(this.jButton3, new AbsoluteConstraints(240, 20, 100, 30));
        this.directory.addInputMethodListener(new InputMethodListener() {
            public void inputMethodTextChanged(InputMethodEvent evt) {
                GuiMain.this.directoryInputMethodTextChanged(evt);
            }

            public void caretPositionChanged(InputMethodEvent evt) {
            }
        });
        this.directory.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiMain.this.directoryActionPerformed(evt);
            }
        });
        this.directory.addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent evt) {
                GuiMain.this.directoryKeyPressed(evt);
            }
        });
        this.jPanel1.add(this.directory, new AbsoluteConstraints(20, 20, 160, 30));
        this.content.addTextListener(new TextListener() {
            public void textValueChanged(TextEvent evt) {
                GuiMain.this.contentTextValueChanged(evt);
            }
        });
        this.jPanel1.add(this.content, new AbsoluteConstraints(20, 60, 160, 30));
        this.jPanel3.add(this.jPanel1, new AbsoluteConstraints(10, 10, 360, 620));
        this.getContentPane().add(this.jPanel3, new AbsoluteConstraints(30, 30, 940, 670));
        this.jMenu1.setText("文件");
        this.jMenuItem1.setAccelerator(KeyStroke.getKeyStroke(65, 1));
        this.jMenuItem1.setText("类帮助");
        this.jMenu1.add(this.jMenuItem1);
        this.jMenuBar1.add(this.jMenu1);
        this.jMenu2.setText("编辑");
        this.jMenuItem2.setText("文件编辑");
        this.jMenuItem2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiMain.this.jMenuItem2ActionPerformed(evt);
            }
        });
        this.jMenu2.add(this.jMenuItem2);
        this.jMenuBar1.add(this.jMenu2);
        this.setJMenuBar(this.jMenuBar1);
        this.pack();
    }

    private void searchActionPerformed(ActionEvent evt) {
        String cotent = this.content.getText();
        this.setListData(ReadUtil.search(this.listApi, cotent));
    }

    private void jButton3ActionPerformed(ActionEvent evt) {
        this.directoryPath = ReadUtil.OpenFile();
        if(this.directoryPath != null) {
            this.setData(this.directoryPath);
            this.directory.setText(this.directoryPath);
        }

    }

    private void jMenuItem2ActionPerformed(ActionEvent evt) {
        GuiAdd guiadd = new GuiAdd();
        guiadd.setVisible(true);
    }

    private void directoryInputMethodTextChanged(InputMethodEvent evt) {
        System.out.println("内容正在改变");
    }

    private void directoryKeyPressed(KeyEvent evt) {
    }

    private void directoryActionPerformed(ActionEvent evt) {
    }

    private void contentTextValueChanged(TextEvent evt) {
        String cotent = this.content.getText();
        this.setListData(ReadUtil.search(this.listApi, cotent));
    }

    private void formComponentResized(ComponentEvent evt) {
    }

    private void editorComponentResized(ComponentEvent evt) {
    }

    private void initView() {
        this.jTable1.addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent e) {
                if(e.getKeyCode() == 38) {
                    GuiMain.this.setDataToView(-1);
                }

                if(e.getKeyCode() == 40) {
                    GuiMain.this.setDataToView(1);
                }

            }
        });
    }
}
